<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>filter</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	</head>
	<body>
		<div>
			<div>
				Include:
				<input type="checkbox" name="nin" id="nin01" value="01" /><label for="nin01">01</label>
				<input type="checkbox" name="nin" id="nin02" value="02" /><label for="nin02">02</label>
				<input type="checkbox" name="nin" id="nin03" value="03" /><label for="nin03">03</label>
				<input type="checkbox" name="nin" id="nin04" value="04" /><label for="nin04">04</label>
				<input type="checkbox" name="nin" id="nin05" value="05" /><label for="nin05">05</label>
				<input type="checkbox" name="nin" id="nin06" value="06" /><label for="nin06">06</label>
				<input type="checkbox" name="nin" id="nin07" value="07" /><label for="nin07">07</label>
				<input type="checkbox" name="nin" id="nin08" value="08" /><label for="nin08">08</label>
				<input type="checkbox" name="nin" id="nin09" value="09" /><label for="nin09">09</label>
				<input type="checkbox" name="nin" id="nin10" value="10" /><label for="nin10">10</label>
				<input type="checkbox" name="nin" id="nin11" value="11" /><label for="nin11">11</label>
				<br />
				Exclude:
				<input type="checkbox" name="nout" id="nout01" value="01" /><label for="nout01">01</label>
				<input type="checkbox" name="nout" id="nout02" value="02" /><label for="nout02">02</label>
				<input type="checkbox" name="nout" id="nout03" value="03" /><label for="nout03">03</label>
				<input type="checkbox" name="nout" id="nout04" value="04" /><label for="nout04">04</label>
				<input type="checkbox" name="nout" id="nout05" value="05" /><label for="nout05">05</label>
				<input type="checkbox" name="nout" id="nout06" value="06" /><label for="nout06">06</label>
				<input type="checkbox" name="nout" id="nout07" value="07" /><label for="nout07">07</label>
				<input type="checkbox" name="nout" id="nout08" value="08" /><label for="nout08">08</label>
				<input type="checkbox" name="nout" id="nout09" value="09" /><label for="nout09">09</label>
				<input type="checkbox" name="nout" id="nout10" value="10" /><label for="nout10">10</label>
				<input type="checkbox" name="nout" id="nout11" value="11" /><label for="nout11">11</label>
				<br />
				Link:
				<input type="checkbox" name="nlink" id="nlink1" /><label for="nlink1" title="共21注">非连</label>
				<input type="checkbox" name="nlink" id="nlink2" /><label for="nlink2" title="共140注">二连&非连</label>
				<input type="checkbox" name="nlink" id="nlink3" /><label for="nlink3" title="共105注">二连&二连</label>
				<input type="checkbox" name="nlink" id="nlink4" /><label for="nlink4" title="共105注">三连&非连</label>
				<input type="checkbox" name="nlink" id="nlink5" /><label for="nlink5" title="共42注">三连&二连</label>
				<input type="checkbox" name="nlink" id="nlink6" /><label for="nlink6" title="共42注">四连</label>
				<input type="checkbox" name="nlink" id="nlink7" /><label for="nlink7" title="共7注">五连</label>
				<button type="button" onclick="$('input[name=nlink]').attr('checked', true)">All</button>
				<button type="button" onclick="$('input[name=nlink]').attr('checked', false)">All Not</button>
				<br />
				Sum:
				<input type="checkbox" name="nsum" id="nsum01" value="15~21" /><label for="nsum01" title="共29注">15~21</label>
				<input type="checkbox" name="nsum" id="nsum02" value="22~23" /><label for="nsum02" title="共28注">22~23</label>
				<input type="checkbox" name="nsum" id="nsum03" value="24~24" /><label for="nsum03" title="共19注">24</label>
				<input type="checkbox" name="nsum" id="nsum04" value="25~25" /><label for="nsum04" title="共23注">25</label>
				<input type="checkbox" name="nsum" id="nsum05" value="26~26" /><label for="nsum05" title="共25注">26</label>
				<input type="checkbox" name="nsum" id="nsum06" value="27~27" /><label for="nsum06" title="共29注">27</label>
				<input type="checkbox" name="nsum" id="nsum07" value="28~28" /><label for="nsum07" title="共30注">28</label>
				<input type="checkbox" name="nsum" id="nsum08" value="29~29" /><label for="nsum08" title="共32注">29</label>
				<input type="checkbox" name="nsum" id="nsum09" value="30~30" /><label for="nsum09" title="共32注">30</label>
				<input type="checkbox" name="nsum" id="nsum10" value="31~31" /><label for="nsum10" title="共32注">31</label>
				<input type="checkbox" name="nsum" id="nsum11" value="32~32" /><label for="nsum11" title="共30注">32</label>
				<input type="checkbox" name="nsum" id="nsum12" value="33~33" /><label for="nsum12" title="共29注">33</label>
				<input type="checkbox" name="nsum" id="nsum13" value="34~34" /><label for="nsum13" title="共25注">34</label>
				<input type="checkbox" name="nsum" id="nsum14" value="35~35" /><label for="nsum14" title="共23注">35</label>
				<input type="checkbox" name="nsum" id="nsum15" value="36~36" /><label for="nsum15" title="共19注">36</label>
				<input type="checkbox" name="nsum" id="nsum16" value="37~38" /><label for="nsum16" title="共28注">37~38</label>
				<input type="checkbox" name="nsum" id="nsum17" value="39~45" /><label for="nsum17" title="共29注">39~45</label>
				<button type="button" onclick="$('input[name=nsum]').attr('checked', true)">All</button>
				<button type="button" onclick="$('input[name=nsum]').attr('checked', false)">All Not</button>
				<br />
				Jioubi:
				<input type="checkbox" name="jioubi" id="jioubi01" value="0:5" /><label for="jioubi01" title="共1注">0:5</label>
				<input type="checkbox" name="jioubi" id="jioubi02" value="1:4" /><label for="jioubi02" title="共30注">1:4</label>
				<input type="checkbox" name="jioubi" id="jioubi03" value="2:3" /><label for="jioubi03" title="共150注">2:3</label>
				<input type="checkbox" name="jioubi" id="jioubi04" value="3:2" /><label for="jioubi04" title="共200注">3:2</label>
				<input type="checkbox" name="jioubi" id="jioubi05" value="4:1" /><label for="jioubi05" title="共75注">4:1</label>
				<input type="checkbox" name="jioubi" id="jioubi06" value="5:0" /><label for="jioubi06" title="共6注">5:0</label>
				<button type="button" onclick="$('input[name=jioubi]').attr('checked', true)">All</button>
				<button type="button" onclick="$('input[name=jioubi]').attr('checked', false)">All Not</button>
				<br />
				Samelast:
				<input type="checkbox" name="samelast" id="samelast01" /><label for="samelast01" title="1个相同">1</label>
				<input type="checkbox" name="samelast" id="samelast02" /><label for="samelast02" title="2个相同">2</label>
				<input type="checkbox" name="samelast" id="samelast03" /><label for="samelast03" title="3个相同">3</label>
				<input type="checkbox" name="samelast" id="samelast04" /><label for="samelast04" title="4个相同">4</label>
				<input type="checkbox" name="samelast" id="samelast05" /><label for="samelast05" title="5个相同">5</label>
				<button type="button" onclick="$('input[name=samelast]').attr('checked', true)">All</button>
				<button type="button" onclick="$('input[name=samelast]').attr('checked', false)">All Not</button>
				<br />
				Exlast:
				<input type="checkbox" name="exlast" id="exlast01" /><label for="exlast01">Excluding last</label>
				<br />
				<button type="button" onclick="getNos()">Get</button>
				<button type="button" onclick="clearNos()">Clear</button>
				<button type="button" onclick="resetNos()">Reset</button>
				共<span id="count">0</span>注
			</div>
			
			<div id="info">
				<textarea id="paper" rows="20" cols="40"></textarea>
			</div>
		</div>
		
		<script type="text/javascript" src="../../js/jquery-1.3.2.min.js"></script>
		<script type="text/javascript">
			var baseNos = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
			var baseNosArr = zuhe(baseNos);
			var linkMap = {'nlink1': 'is0L', 'nlink2': 'is2L0L', 'nlink3': 'is2L2L', 'nlink4': 'is3L0L', 'nlink5': 'is3L2L', 'nlink6': 'is4L', 'nlink7': 'is5L'};
			
			$(document).ready(function() {
				
			});
			
			function getNos() {
				var nosArr = F1(baseNosArr);
				nosArr = F2(nosArr);
				nosArr = F3(nosArr);
				nosArr = F4(nosArr);
				nosArr = F5(nosArr);
				nosArr = FX(nosArr);
				//nosArr = FY(nosArr);
				print(nosArr);
			}
			
			function clearNos() {
				$('#paper').val('');
				$('#count').html(0);
			}
			
			function resetNos() {
				$('input[name=nin]').attr('checked', false);
				$('input[name=nout]').attr('checked', false);
				$('input[name=nlink]').attr('checked', false);
				$('input[name=nsum]').attr('checked', false);
				$('input[name=jioubi]').attr('checked', false);
				$('input[name=samelast]').attr('checked', false);
				$('input[name=exlast]').attr('checked', false);
				clearNos();
			}
			
			function F1(nosArr) {
				if (nosArr.length == 0) {
					return;
				}
				var incl = [];
				$("input:checkbox[name=nin]:checked").each(function() {
					incl.push(parseInt(this.value, 10));
				});
				var newNosArr = [];
				for (var i = 0; i < nosArr.length; i++) {
					if (include(nosArr[i], incl)) {
						newNosArr.push(nosArr[i]);
					}
				}
				return newNosArr;
			}
			
			function F2(nosArr) {
				if (nosArr.length == 0) {
					return;
				}
				var excl = [];
				$("input:checkbox[name=nout]:checked").each(function() {
					excl.push(parseInt(this.value, 10));
				});
				var newNosArr = [];
				for (var i = 0; i < nosArr.length; i++) {
					if (exclude(nosArr[i], excl)) {
						newNosArr.push(nosArr[i]);
					}
				}
				return newNosArr;
			}
			
			function F3(nosArr) {
				if (nosArr.length == 0) {
					return;
				}
				var selLinks = [];
				$("input:checkbox[name=nlink]:checked").each(function() {
					selLinks.push(linkMap[this.id]);
				});
				var newNosArr = [];
				for (var i = 0; i < nosArr.length; i++) {
					if (link(nosArr[i], selLinks)) {
						newNosArr.push(nosArr[i]);
					}
				}
				return newNosArr;
			}
			
			function F4(nosArr) {
				if (nosArr.length == 0) {
					return;
				}
				var selSums = [];
				$("input:checkbox[name=nsum]:checked").each(function() {
					selSums.push(this.value.split("~"));
				});
				var newNosArr = [];
				for (var i = 0; i < nosArr.length; i++) {
					if (sum(nosArr[i], selSums)) {
						newNosArr.push(nosArr[i]);
					}
				}
				return newNosArr;
			}
			
			function F5(nosArr) {
				if (nosArr.length == 0) {
					return;
				}
				var selJioubis = [];
				$("input:checkbox[name=jioubi]:checked").each(function() {
					selJioubis.push(this.value.split(":"));
				});
				var newNosArr = [];
				for (var i = 0; i < nosArr.length; i++) {
					if (jioubi(nosArr[i], selJioubis)) {
						newNosArr.push(nosArr[i]);
					}
				}
				return newNosArr;
			}
			
			function FX(nosArr) {
				if (nosArr.length == 0) {
					return;
				}
				var lastNos = [];
				if ($("input:checkbox[name=exlast]")[0].checked) {
					lastNos = [[02, 03, 06, 07, 10], [02, 03, 05, 08, 09], [01, 03, 04, 06, 10], [05, 06, 07, 10, 11], [01, 04, 05, 08, 11], [03, 06, 08, 09, 10], [01, 02, 07, 08, 11], [01, 02, 03, 04, 08]];
				}
				var newNosArr = [];
				for (var i = 0; i < nosArr.length; i++) {
					if (exlast(nosArr[i], lastNos)) {
						newNosArr.push(nosArr[i]);
					}
				}
				return newNosArr;
			}
			/*
			function FY(nosArr) {
				if (nosArr.length == 0) {
					return;
				}
				var selJioubis = [];
				$("input:checkbox[name=jioubi]:checked").each(function() {
					selJioubis.push(this.value.split(":"));
				});
				var newNosArr = [];
				for (var i = 0; i < nosArr.length; i++) {
					if (exlast(nosArr[i], lastNos)) {
						newNosArr.push(nosArr[i]);
					}
				}
				return newNosArr;
			}
			*/
			function print(nosArr) {
				var str = "";
				for (var i = 0; i < nosArr.length; i++) {
					str += toString(nosArr[i]) + "\n";
				}
				$("#paper").val(str);
				$("#count").html(nosArr.length);
			}
			
			function toString(arr) {
				var str = "";
				for (var i = 0; i < arr.length; i++) {
					str +=  "," + (arr[i] < 10 ? "0" + arr[i] : arr[i]);
				}
				return str.substring(1);
			}
			
			function include(arr, incl) {
				if (incl.length == 0) {
					return true;
				}
				for (var i = 0; i < incl.length; i++) {
					var b = false;
					for (var j = 0; j < arr.length; j++) {
						if (incl[i] == arr[j]) {
							b = true;
							break;
						}
					}
					if (!b) {
						return false;
					}
				}
				return true;
			}
			
			function exclude(arr, excl) {
				if (excl.length == 0) {
					return true;
				}
				for (var i = 0; i < excl.length; i++) {
					for (var j = 0; j < arr.length; j++) {
						if (arr[j] == excl[i]) {
							return false;
						}
					}
				}
				return true;
			}
			
			function link(arr, selLinks) {
				if (selLinks.length == 0) {
					return true;
				}
				for (var i = 0; i < selLinks.length; i++) {
					var exp = selLinks[i] + "(arr)";
					if (eval(exp)) {
						return true;
					}
				}
				return false;
			}
			
			function sum(arr, selSums) {
				if (selSums.length == 0) {
					return true;
				}
				var s = getSum(arr);
				for (var i = 0; i < selSums.length; i++) {
					if (s >= selSums[i][0] && s <= selSums[i][1]) {
						return true;
					}
				}
				return false;
			}
			
			function jioubi(arr, selJioubis) {
				if (selJioubis.length == 0) {
					return true;
				}
				var n = 0;
				for (var i = 0; i < arr.length; i++) {
					if (arr[i] % 2 == 1) {
						n++;
					}
				}
				for (var i = 0; i < selJioubis.length; i++) {
					if (selJioubis[i][0] == n) {
						return true;
					}
				}
				return false;
			}
			
			function exlast(arr, lastNos) {
				if (lastNos.length == 0) {
					return true;
				}
				var a = 0;
				if (lastNos.length > 30) {
					a = lastNos.length - 30;
				}
				for (var i = a; i < lastNos.length; i++) {
					var b = true;
					for (var j = 0; j < arr.length; j++) {
						if (lastNos[i][j] != arr[j]) {
							b = false;
							break;
						}
					}
					if (b) {
						return false;
					}
				}
				return true;
			}
			
			function zuhe(nos) {
				var resArr = [];
				for (var i = 0; i < nos.length - 4; i++) {
					var nos1 = nos.concat();
					nos1.splice(0, i + 1);
					for (var j = 0; j < nos1.length - 3; j++) {
						var nos2 = nos1.concat();
						nos2.splice(0, j + 1);
						for (var k = 0; k < nos2.length - 2; k++) {
							var nos3 = nos2.concat();
							nos3.splice(0, k + 1);
							for (var l = 0; l < nos3.length - 1; l++) {
								var nos4 = nos3.concat();
								nos4.splice(0, l + 1);
								for (var m = 0; m < nos4.length; m++) {
									resArr.push([nos[i], nos1[j], nos2[k], nos3[l], nos4[m]]);
								}
							}
						}
					}
				}
				return resArr;
			}
			
			function is5L(a) {
				if (a[0] == a[1] - 1 && a[1] == a[2] - 1 && a[2] == a[3] - 1 && a[3] == a[4] - 1) {
					return true;
				}
				return false;
			}
			function is4L(a) {
				if ((a[0] == a[1] - 1 && a[1] == a[2] - 1 && a[2] == a[3] - 1 && a[3] != a[4] - 1)
					|| (a[0] != a[1] - 1 && a[1] == a[2] - 1 && a[2] == a[3] - 1 && a[3] == a[4] - 1)) {
					return true;
				}
				return false;
			}
			function is3L2L(a) {
				var s = sub(a);
				var n = 0;
				for (var i = 0; i < s.length; i++) {
					if (s.charAt(i) == '1') {
						n++;
					}
				}
				return n == 3 && s.indexOf("111") == -1;
			}
			function is3L0L(a) {
				var s = sub(a);
				var n = 0;
				for (var i = 0; i < s.length; i++) {
					if (s.charAt(i) == '1') {
						n++;
					}
				}
				return n == 2 && s.indexOf("11") != -1;
			}
			function is2L2L(a) {
				var s = sub(a);
				var n = 0;
				for (var i = 0; i < s.length; i++) {
					if (s.charAt(i) == '1') {
						n++;
					}
				}
				return n == 2 && s.indexOf("11") == -1;
			}
			function is2L0L(a) {
				var s = sub(a);
				var n = 0;
				for (var i = 0; i < s.length; i++) {
					if (s.charAt(i) == '1') {
						n++;
					}
				}
				return n == 1;
			}
			function is0L(a) {
				if (a[0] != a[1] - 1 && a[1] != a[2] - 1 && a[2] != a[3] - 1 && a[3] != a[4] - 1) {
					return true;
				}
				return false;
			}
			function sub(a) {
				var s = "";
				for (var i = 0; i < a.length - 1; i++) {
					s += a[i + 1] - a[i];
				}
				return s;
			}
			function getSum(a) {
				return a[0] + a[1] + a[2] + a[3] + a[4];
			}
	 	</script>
	</body>
</html>
